package com.yeung.exam;

import java.util.Scanner;

/**
 * 网易2019秋招笔试题
 */
public class 翻转反转 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long groups = scanner.nextLong();
        while (groups > 0) {
            long n = scanner.nextLong();
            long m = scanner.nextLong();
            if (n > m) {
                long t = m;
                m = n;
                n = t;
            }
            if (n == 1 && m == 1) {
                System.out.println(1);
                continue;
            }
            if (n == 1) {
                System.out.println(m - 2);
                continue;
            }
            System.out.println((n - 2) * (m - 2));
            groups--;
        }
    }

}
